package com.example.javaairportflightanalysis.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.example.javaairportflightanalysis.common.ApiRestResponse;
import com.example.javaairportflightanalysis.exception.MyExceptionEnum;
import com.example.javaairportflightanalysis.service.DfdlService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author shen
 */
@RestController
@RequestMapping("/dfdl")
@SaIgnore

@CrossOrigin(origins = "*",maxAge = 3600)
public class DfdlController {
    @Resource
    DfdlService dfdlService;
    @GetMapping("/getAApno2")
    public ApiRestResponse getAApno2(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws ParseException {
        PageInfo pageInfo = dfdlService.getAApno2(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @GetMapping("/getAApno3")
    public ApiRestResponse getAApno3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws ParseException {
        PageInfo pageInfo = dfdlService.getAApno3(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @GetMapping("/getDApno2")
    public ApiRestResponse getDApno2(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws ParseException {
        PageInfo pageInfo = dfdlService.getDApno2(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @GetMapping("/getDApno3")
    public ApiRestResponse getDApno3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws ParseException {
        PageInfo pageInfo = dfdlService.getDApno3(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @GetMapping("/selectA2401")
    public ApiRestResponse selectA2401(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,
                                       String dfltFlno, String dtime,
                                       String dfltAwcd, String apcd,
                                        String fptt, String fplt) throws ParseException {
        PageInfo pageInfo = dfdlService.selectA2401(dfltFlno,dtime, dfltAwcd, apcd, fptt, fplt, pageNum, pageSize);
        if (pageInfo.getPageSize()==0) {
            return ApiRestResponse.error(MyExceptionEnum.NO_DATA);
        }
        return ApiRestResponse.success(pageInfo);
    }

    @GetMapping("/selectD2401")
    public ApiRestResponse selectD2401(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,
                                       String dfltFlno, String dtime,
                                       String dfltAwcd, String apcd,
                                       String fptt, String fplt) throws ParseException {
        PageInfo pageInfo = dfdlService.selectD2401(dfltFlno,dtime, dfltAwcd, apcd, fptt, fplt, pageNum, pageSize);
        if (pageInfo.getSize() == 0) {
            return ApiRestResponse.error(MyExceptionEnum.NO_DATA);
        }
        return ApiRestResponse.success(pageInfo);
    }
    @GetMapping("/selectDApno3")
    public ApiRestResponse selectDApno3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,
                                        String dfltFlno, String dtime,
                                        String apcd, String transitApcd) throws ParseException {
        PageInfo pageInfo = dfdlService.selectDApno3(dfltFlno,dtime, apcd, transitApcd, pageNum, pageSize);
        if (pageInfo.getSize() == 0) {
            return ApiRestResponse.error(MyExceptionEnum.NO_DATA);
        }
        return ApiRestResponse.success(pageInfo);
    }
    @GetMapping("/selectAApno3")
    public ApiRestResponse selectAApno3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,
                                        String dfltFlno, String dtime,
                                        String apcd, String transitApcd) throws ParseException {
        PageInfo pageInfo = dfdlService.selectAApno3(dfltFlno,dtime, apcd, transitApcd, pageNum, pageSize);
        if (pageInfo.getSize() == 0) {
            return ApiRestResponse.error(MyExceptionEnum.NO_DATA);
        }
        return ApiRestResponse.success(pageInfo);
    }

}
